<?php
/* ******************************
	Incoming Tasks aJax actions
   ******************************
*/
	include('../../includes/classes/core.php');
	$action = $_REQUEST['act'];
	$start		=	$_REQUEST['start'];
    $end		=	$_REQUEST['end'];
	
	switch ($action) {
	    case 'get_list':
    	    $count = $_REQUEST['count'];
    	    
    	    $rResult = mysql_query("
						SELECT  
    	    		    	    		sale_transaction_detail.id                  AS id,
    	    							sale_transaction.end_date, 

                 					                   production.name                  AS product,
    	    					 sale_transaction_detail.product_quantity                 AS quantity,
    	    										   object.`name`                    AS obj_name,        
                                 ROUND(sale_transaction_detail.product_quantity  *  sale_transaction_detail.cost, 2) AS sumCost
																
								 FROM          sale_transaction 
    	    		             LEFT JOIN  sale_transaction_detail ON sale_transaction.id = sale_transaction_detail.transaction_id 
    	    		             LEFT JOIN  production ON sale_transaction_detail.production_id = production.id        
    	    		             LEFT JOIN 	object ON sale_transaction.object_id = object.id

													 LEFT JOIN users ON sale_transaction.user_id = users.id
								 WHERE 		sale_transaction.`status` = 0 AND sale_transaction.end_date >= '$start' AND sale_transaction.end_date <= '$end'

						
    	    		");
			
			$output = array(
				"aaData"	=> array()
			);
			
			while ( $aRow = mysql_fetch_array( $rResult ) )
			{
				$row = array();
				for ( $i = 0 ; $i < $count ; $i++ )
				{
					/* General output */
					$row[] = $aRow[$i];
				}
				$output['aaData'][] = $row;
			}
			
			echo json_encode( $output );

	        break;	    
	    default:
	       	echo "null";
	}
?>